package com.autocar.reader.adapter;

import java.util.ArrayList;
import java.util.List;

import com.autocar.reader.R;
import com.autocar.reader.bean.ChatBean;
import com.autocar.reader.bean.RequestBean;
import com.autocar.reader.util.ImageUtils;
import com.org.any.autocar.fragment.IopenAddFrends;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatTrendsAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	IopenAddFrends addFrends = null;

	public ChatTrendsAdapter(Context context, IopenAddFrends addFrends) {
		inflater = LayoutInflater.from(context);
		this.addFrends = addFrends;
	}

	List<ChatBean> wlist = new ArrayList<ChatBean>();

	public void setWList(List<ChatBean> wlist1) {
		this.wlist = wlist1;
		if (wlist != null) {
			notifyDataSetChanged();
		}
	}

	@Override
	public int getCount() {
		return wlist.size();
	}

	@Override
	public Object getItem(int position) {
		return wlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.chat_trends_item, null);
		}
		TextView name = (TextView) convertView
				.findViewById(R.id.comment_list_tv_name);
		TextView addtime = (TextView) convertView
				.findViewById(R.id.comment_list_tv_time);
		TextView content = (TextView) convertView
				.findViewById(R.id.comment_list_tv_content);
		ImageView author = (ImageView) convertView
				.findViewById(R.id.chat_trends_item_iv_pic);
		final ChatBean bean = wlist.get(position);
		addtime.setText(bean.getAddtime());
		name.setText(bean.getUname());
		content.setText(bean.getMsg());
		ImageUtils.fb.display(author, bean.getPhone());
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addFrends.toChat(bean);
			}
		});
		author.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addFrends.openAuthor(bean.getUid());
			}
		});

		return convertView;
	}

}
